import java.util.Arrays;
import java.util.Random;


public class SampleDataProvider {
	
	private int[] unsorted;
	private int[] sorted = null;
	
	/***
	 * Generate 'count' random number of length 'bits'.
	 * Numbers will be in range [2^(bits-1) .. (2^bits)-1]
	 * @param count number of numbers to generate
	 * @param bits bit length of the numbers
	 */
	public SampleDataProvider(int count, int bits) {
		super();
		assert(bits > 0);
		assert(bits < 33);	// 32 bits max, because of using integers
		this.unsorted = new int[count];
		
		Random rand = new Random();
		for(int i=0; i<count; i++)
		{
			int low = (1 << (bits -1)); 			// 2^(n-1)
			unsorted[i] = low + rand.nextInt(low);
		}
	}

	public int[] getUnsorted() {
		return unsorted;
	}

	
	public int[] getSorted() {
		if (sorted == null) {
			sorted = unsorted.clone();
			Arrays.sort(sorted);
		}
		
		return sorted;
	}
	
	private void printArray(int[] a)
	{
		for (int i = 0; i < a.length; i++) {
			System.out.format("%3d ", a[i]);
		}
		System.out.println();
	}
	
	private void printUnsorted()
	{
		printArray(unsorted);
	}
	
	private void printSorted()
	{
		printArray(sorted);
	}
	
	public static void main(String[] args)
	{
		SampleDataProvider sdp = new SampleDataProvider(10, 5);
		sdp.printUnsorted();
		sdp.printSorted();
	}

}
